#ifndef __OBJECT__
#define __OBJECT__
/*--------------------------------------------------------------------------------*/
#include "primitives.h"
#include "debug.h"
#include "text.h"
/*--------------------------------------------------------------------------------*/
#define OBJECT_DestructedRefCount  			2147483647
/*--------------------------------------------------------------------------------*/
class OBJECT
{

public:

    OBJECT() :
        RefCount( 0 ),
        ItIsAllocated( false )
    {

    }

	virtual ~OBJECT()
	{
		DEBUG_Require( !RefCount );
		RefCount = OBJECT_DestructedRefCount;
	}

	inline VOID AddRef()
	{
	    ++RefCount;
	}

	inline VOID RemoveRef()
	{
	    --RefCount;

	    if ( !RefCount && ItIsAllocated )
		{
			DEBUG_Log( "Deleting " );
	    	DEBUG_LogLine( GetClassName() );

			//this->~OBJECT();
			delete this;
		}
	}

	inline COUNT GetRefCount()
	{
	    return RefCount;
	}

	inline VOID SetIsAllocated()
	{
		ItIsAllocated = true;
	}

	virtual const CHAR * GetClassName() const
	{
		return "OBJECT";
	}

private:

	COUNT
		RefCount;
	BOOL
		ItIsAllocated; // :TODO: Remove this and use first byte of refcount.
};
/*--------------------------------------------------------------------------------*/
#endif


